
function previewImg(index){
    			console.log("index---"+index);
					var pswpElement = document.querySelectorAll('.pswp')[0];
					var items = [];
					//获取图片数据并填充近数组
					hui('.imgs').each(function(eimg){
					
						console.log(JSON.stringify(eimg));

						console.log("eimg.getAttribute('src')---"+ eimg.getAttribute('src'));
						var imgObj = {src:eimg.getAttribute('src'), w:eimg.naturalWidth, h:eimg.naturalHeight};
						items.push(imgObj);
					});
					var options = {index: index};
					var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
					gallery.init();
				}
$(function() {

	function showAlert(msg) {
		//							alert(msg);

		swal("", msg, "warning");

	} //判断字符是否为空的方法

	//接收工单
	function work_jieshou() {
		var workId = localStorage.getItem("workid");
		var path = urlManager.work_jieshou() + "?id=" + workId;
		var username = apiManage.getUsername();
		var sec = apiManage.getSecPwd();
		var time = apiManage.getNow();
		var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
		var paramKey = hex_md5(key);
		hui.loading("");
		$.ajax({
			type: "GET",
			url: path,
			beforeSend: function(request) {
				request.setRequestHeader("loginName", username);
				request.setRequestHeader("time", time);
				request.setRequestHeader("sign", paramKey);
				request.setRequestHeader("Content-Type", "application/text");

			},
			success: function(result) {
				hui.closeLoading();

				console.log("待接收 -处理:" + JSON.stringify(result));
				if(result.searchFromPage == null) {
					swal({  
							title: "接收失败",
							  text: "",
							  type: "error",
							  showCancelButton: false,
							  confirmButtonColor: "#DD6B55",
							  confirmButtonText: "确认",
							  cancelButtonText: "取消",
							  closeOnConfirm: true,
							  closeOnCancel: false
						},
						function(isConfirm) {  
							if(isConfirm) {
								//hui.open("work_list.html?time="+apiManage.getNow(), {}, true, {});	
								  } else {  }
						});
				} else {
					swal({  
							title: "接收成功",
							  text: "",
							  type: "success",
							  showCancelButton: false,
							  confirmButtonColor: "#DD6B55",
							  confirmButtonText: "确认",
							  cancelButtonText: "取消",
							  closeOnConfirm: true,
							  closeOnCancel: false
						},
						function(isConfirm) {  
							if(isConfirm) {
								hui.open("work_list.html?time=" + apiManage.getNow(), {}, true, {});  
							} else {  }
						});
				}

			
			}

		});
	}

	//进一步处理
	function work_jybcl() {
		var workId = localStorage.getItem("workid");
		var path = urlManager.work_jybcl();
		//				+"?id=" + workId+"&remarks="+encodeURIComponent(sp.remark)
		var username = apiManage.getUsername();
		var sec = apiManage.getSecPwd();
		var time = apiManage.getNow();
		var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
		var paramKey = hex_md5(key);
		//data:{id:workId,remarks:sp.remark},

		console.log("path----" + path);

		
		var params = {
			id: workId,
			remarks: sp.remark
		};
		
		if(sp.remark==null||sp.remark==''){
			hui.toast('请填写进一步处理备注信息');
			return;
		}
		hui.loading("");
		console.log("params------" + JSON.stringify(params));
		$.ajax({
			type: "POST",
			url: path,
			data: params,
			beforeSend: function(request) {
				request.setRequestHeader("loginName", username);
				request.setRequestHeader("time", time);
				request.setRequestHeader("sign", paramKey);
				//						request.setRequestHeader("Content-Type", "application/text");

			},
			success: function(result) {

				hui.closeLoading();
				console.log("进一步-处理:" + JSON.stringify(result));

				swal({  
						title: "进一步处理成功",
						  text: "",
						  type: "success",
						  showCancelButton: false,
						  confirmButtonColor: "#DD6B55",
						  confirmButtonText: "确认",
						  cancelButtonText: "取消",
						  closeOnConfirm: true,
						  closeOnCancel: false
					},
					function(isConfirm) {  
						if(isConfirm) {
							hui.open("work_list.html?time=" + apiManage.getNow(), {}, true, {});  
						} else {  }
					});

			}

		});
	}

	//完成
	function work_over() {
		//"?id=" + workId+"&remarks="+encodeURIComponent(sp.remark)+"&alarmReason="+encodeURIComponent(sp.alarmReason)

		var workId = localStorage.getItem("workid");
		var path = urlManager.work_over();

		var username = apiManage.getUsername();
		var sec = apiManage.getSecPwd();
		var time = apiManage.getNow();
		var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
		var paramKey = hex_md5(key);

		console.log("点击完成path-----" + path + "   " + paramKey);

		console.log("key-----" + key);

	if(sp.alarmReason==null||sp.alarmReason==''){
			hui.toast('请填写告警原因');
			return;
		}

		console.log("点击完成params---" + JSON.stringify({
			id: workId,
			remarks: sp.remark,
			alarmReason: sp.alarmReason
		}));
		$.ajax({
			type: "POST",
			url: path,
			data: {
				id: workId,
				remarks: sp.remark,
				alarmReason: sp.alarmReason,
				scenePhoto:sp.params.url
			},
			beforeSend: function(request) {
				request.setRequestHeader("loginName", username);
				request.setRequestHeader("time", time);
				request.setRequestHeader("sign", paramKey);
				//	request.setRequestHeader("Content-Type", "application/text");

			},
			success: function(result) {
				hui.closeLoading();

				//		            hui.closeLoading();
				console.log("完成:" + JSON.stringify(result));

				swal({  
						title: "工单已完成",
						  text: "",
						  type: "success",
						  showCancelButton: false,
						  confirmButtonColor: "#DD6B55",
						  confirmButtonText: "确认",
						  cancelButtonText: "取消",
						  closeOnConfirm: true,
						  closeOnCancel: false
					},
					function(isConfirm) {  
						if(isConfirm) {
							hui.open("work_list.html?time=" + apiManage.getNow(), {}, true, {});  
						} else {  }
					});

			}

		});
	}

	var sp = new Vue({
		el: "#wrapper",
		data: {
			params:{url:""}, 
				imgs: [],
			work: {},
			gjTime: "",
			jg: {},
			gaoj: {},
			zd: {},
			worklist: [],
			timeDiffArray: [],
			workState: "",
			workListInfo: {},
			worksArray: [],
			status: "",
			remark: "",
			alarmReason: ""
		},

		created: function() {
			var type = localStorage.getItem("type");
			console.log("type--"+type);
			if(type == 'view') {
				
				$(".block_two").hide();
			}
		},

		methods: {
				showImg:function(e){
						  var index = $(e.currentTarget).index();
			    		previewImg(index);
					},
					cutImgs:function(imgUrl){
						if(imgUrl!=null&&imgUrl!=''){
							return imgUrl.split(",");
						}
					},
			nav: function(lat, lng) {
				localStorage.setItem("lat", lat);
				localStorage.setItem("lng", lng);

				console.log("lat---" + lat);
				console.log("lng---" + lng);

				hui.open("/modules/gisTerminal/navigation.html?s=" + apiManage.getNow(), {}, true, {});
			},

			//	型号规格(1圆形，2方形，3外方内圆，4其他)
			showModel: function(param) {

				if(param == '1') {
					return "圆形";
				} else if(param == '2') {
					return "方形";
				} else if(param == '3') {
					return "外方内圆";
				} else {
					return "其他";

				}
			},

			showStatus: function(param) {
				//0无告警；1一般告警；2严重告警；3工单处理中
				if(param == '0') {
					return "无告警";
				} else if(param == '1') {
					return "一般告警";
				} else if(param == '2') {
					return "严重告警";
				} else {
					return "工单处理中";

				}
			},
			showMetal: function(param) {

				function getCZText(p_text) {
					if(p_text == '1') {
						return "复合材料";
					} else if(p_text == '2') {
						return "铸铁";
					} else if(p_text == '3') {
						return "水泥";
					} else {
						return "其他";
					}
				}
				if(param == null || param == "") {
					return "";
				}
				var czArray = param.split(",");
				var czString = "";
				for(var i = 0; i < czArray.length; i++) {
					var cell = czArray[i];
					czString += " ";
					czString += getCZText(cell);
				}
				return czString;

			},
			showPrjStatus: function(param) {

				if(param == '0') {
					return "无告警";
				} else if(param == '1') {
					return "一般告警";
				} else if(param == '2') {
					return "严重告警";
				} else {
					return "工单处理中";
				}
			},
			showAlerm: function(param) {
				if(param == '1') {
					return "一般告警";
				} else {
					return "严重告警";
				}
			},

			showChannel: function(param) {
				if(param == '1') {
					return "新建";
				} else if(param == '2') {
					return "巡检";
				} else if(param == '3') {
					return "告警上报";
				} else {
					return "隐患";
				}
			},
			geshi: function(param) {
				return formatTime(param);
			},
			jybcl: function() {
				work_jybcl();
			},
			chuli: function() {
				work_jieshou();
			},
			over: function() {
				work_over();
			},

			back: function() {
				//						window.history.back(-1);
				hui.back();
			},
			worklist: function() {
				hui.open("work_list.html", {}, true, {});
			}
		}
	});

	function showStatus(param) {
		var text = "";
		//10	新建	work_state	
		//20	待指派	work_state	
		//30	待接收	work_state	
		//40	待处理	work_state	
		//50	进一步处理	work_state	
		//60	已完成	work_state	
		//90	已取消
		if(param == '10') {
			text = '新建';
		} else if(param == '20') {
			text = '待指派';
		} else if(param == '30') {
			text = '待接收';

			$("#chuli").on("click", function() {
				var text = $(this).text();
				console.log(text);
				work_jieshou();　　
			});

		} else if(param == '40') {
			text = '待处理';

			$("#jybcl").on("click", function() {
				var text = $(this).text();
				console.log(text);
				work_jybcl();　　
			});

		} else if(param == '50') {
			text = '进一步处理';

			$("#wanc").on("click", function() {
				var text = $(this).text();
				console.log(text);
				work_over();　　
			});

		} else if(param == '60') {
			text = '已完成';
		} else {
			text = '已取消';
		}

		return text;
	}

	Date.prototype.toLocaleString = function() {
		return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds() + "";
	};

	loadData();

	function loadData() {
		hui.loading("");

		var workId = localStorage.getItem("workid");
		var path = urlManager.workDetai() + "?id=" + workId;
		var username = apiManage.getUsername();
		var sec = apiManage.getSecPwd();
		var time = apiManage.getNow();
		var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
		var paramKey = hex_md5(key);
			console.log("params---"+key+" sign:"+paramKey);
			console.log("path---"+path);

		$.ajax({
			type: "GET",
			url: path,
			beforeSend: function(request) {
				request.setRequestHeader("loginName", username);
				request.setRequestHeader("time", time);
				request.setRequestHeader("sign", paramKey);
				request.setRequestHeader("Content-Type", "application/text");

			},
			success: function(result) {

				hui.closeLoading();
				console.log("工单详情:" + JSON.stringify(result));
				sp.work = result;
//				console.log("sp.work----" + JSON.stringify(sp.work));
				var jg = new Object();
				var gaoj = new Object();

			
				gaoj.resid = result.id;
				gaoj.lastoccurtime = result.createDateStr;
				sp.gjTime = result.createDateStr;
				gaoj.belongStreet = jg.belongStreet;
				//									}

				if(result.gjId) {
					sp.gjTime = result.gjId.occurtime;
				} else {
					sp.gjTime = formatTime(result.createDateStr);

				}

				var workList = result.workProcessList;

				if(result.resTerminal) {
					console.log("有终端信息.....");
					sp.zd = result.resTerminal;
					sp.jg = result.resTerminal.jgId;
				} else {
					//没有终端信息
					console.log("没有终端信息.....");

					//                       	$("#zd_info").hide();
					sp.jg = result.resJg;
				}

				//									if(jg==null){//没有井盖信息
				//										$("#jg_info").hide();
				//									}

				//							sp.jg=jg;
				sp.gaoj = result.gjId;
				sp.worklist = workList;
				readyData();
				sp.workState = showStatus(result.workState);
				sp.status = result.workState;
				//                  		console.log(JSON.stringify(workList));

			}

		});

	}

	//准备数据
	function readyData() {
		var datas = sp.worklist;
		var worksArray = new Array(); //装入列表
		var workListInfo = new Object(); //按状态对应时间
		console.log("准备数据" + JSON.stringify(datas));

		if(datas == null || datas.length == 0) {

			return;
		}
		for(var i = 0; i < datas.length; i++) {
			var cell = datas[i];
			if(cell.thisState == '10') { //工单
				workListInfo.gd = cell;
				worksArray.push(cell);
			} else if(cell.thisState == '30') { //待接收
				workListInfo.djs = cell;
				worksArray.push(cell);
			} else if(cell.thisState == '40') { //处理
				workListInfo.cl = cell;
				worksArray.push(cell);
			} else if(cell.thisState == '60') { //完成
				workListInfo.wc = cell;
				worksArray.push(cell);
			} else {}
		}
		sp.workListInfo = workListInfo;

		sp.worksArray = worksArray;

		//alert('准备数据 底部');

		settingHtml();
		readyTimeDiff();

	}

	//时间差数组
	function readyTimeDiff() {
		var gjTime = sp.gjTime;

		var gdTime = "";
		var djsTime = "";
		var clTime = "";
		var wcTime = "";

//		console.log("sp.workListInfo." + JSON.stringify(sp.workListInfo));
		if(sp.workListInfo.gd != null && sp.gjTime != null) {
			var time = timeDiff(formatTime(sp.gjTime), formatTime(sp.workListInfo.gd.createDateStr));
			gdTime = time;
		}

		if(sp.workListInfo.djs != null) {
			var time = timeDiff(formatTime(sp.workListInfo.gd.createDateStr), formatTime(sp.workListInfo.djs.createDateStr));
			djsTime = time;

		}
		if(sp.workListInfo.cl != null) {
			var time = timeDiff(formatTime(sp.workListInfo.djs.createDateStr), formatTime(sp.workListInfo.cl.createDateStr));
			clTime = time;

		}
		if(sp.workListInfo.wc != null) {
			var time = timeDiff(formatTime(sp.workListInfo.cl.createDateStr), formatTime(sp.workListInfo.wc.createDateStr));
			wcTime = time;

		}
		var readyArray = new Array();
		// sp.timeDiffArray.push(gjTime);
		readyArray.push(gdTime);
		readyArray.push(djsTime);
		readyArray.push(clTime);
		readyArray.push(wcTime);

//		console.log("hahahahha" + JSON.stringify(readyArray));

		sp.timeDiffArray = readyArray;

		var html = "";
		for(var i = 0; i < sp.timeDiffArray.length; i++) {
			html += "<em>" + sp.timeDiffArray[i] + "</em>";
		}
		// 	      return html;
		$(".record_time").html(html);
		//			console.log("--------------------" + html);
	}

	function timeDiff(startTime, endTime) {
		//		console.log("两个时间之间相差多久 并格式化--" + startTime + "  " + endTime);

		startTime = startTime.replace(/\-/g, "/");
		endTime = endTime.replace(/\-/g, "/");

		var diffDate = new Date(endTime).getTime() - new Date(startTime).getTime();
		//console.log("相差--" + diffDate);

		var days = Math.floor(diffDate / (24 * 3600 * 1000));
		var leave1 = diffDate % (24 * 3600 * 1000);
		var hours = Math.floor(leave1 / (3600 * 1000));
		var leave2 = leave1 % (3600 * 1000);
		var minutes = Math.floor(leave2 / (60 * 1000));
		var leave3 = leave2 % (60 * 1000);
		var seconds = Math.round(leave3 / 1000);
		//        console.log(days + " 天 " + hours + "时 " + minutes + " 分 " + seconds + "秒");

		var timeString = "";
		if(days > 0) {
			timeString += days + "天";
				timeString += hours + "小时";

		}
		else{
			if(hours > 0) {
			timeString += hours + "h";
			}
			if(minutes>0){
				timeString += minutes + "m";
			}
			else{
				timeString += seconds + "s";

			}
			
			
		}
	


		//console.log(timeString);

		return timeString;
	}

	//根据数据返回流程视图样式
	function settingHtml() {
		var workListInfo = sp.workListInfo;

				console.log("workListInfo=========="+JSON.stringify(workListInfo));
				
								console.log("sp.worksArray=========="+JSON.stringify(sp.worksArray));

		var worksArray = sp.worksArray;
		var gdTime = "";
		if(workListInfo.gd != null) {
			gdTime = workListInfo.gd.createDateStr;

		}
		var djsTime = "";
		if(workListInfo.djs) {
			djsTime = workListInfo.djs.createDateStr;

		}
		var clTime = "";
		if(workListInfo.cl) {
			clTime = workListInfo.cl.createDateStr;
		}
		var wcTime = "";
		if(workListInfo.wc) {
			wcTime = workListInfo.wc.createDateStr;
		}

		var length = worksArray.length;
		var html = "";

		var gjTime = formatTime(sp.gjTime);
		var styleType = "";
		console.log("length---"+length);
		switch(length) {

			case 0:
				{
					html =
					"  <p>" +
					"      <em class=\"green\">&nbsp;</em>" +
					"      <b>告警</b>" +
					"      <i>" + gjTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em  class=\"white\">&nbsp;</em>" +
					"      <b>工单</b>" +
					"      <i>" + gdTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>待接收</b>" +
					"      <i>" + djsTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>处理</b>" +
					"      <i>" + clTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>完成</b>" +
					"      <i>" + wcTime + "</i>" +
					"    </p>";

				}
				break;

			case 1:
				{
					html =
					"  <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>告警</b>" +
					"      <i>" + gjTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"green\">&nbsp;</em>" +
					"      <b>工单</b>" +
					"      <i>" + gdTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>待接收</b>" +
					"      <i>" + djsTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>处理</b>" +
					"      <i>" + clTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>完成</b>" +
					"      <i>" + wcTime + "</i>" +
					"    </p>";

				}
				break;

			case 2:
				{
					html =
					"  <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>告警</b>" +
					"      <i>" + gjTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>工单</b>" +
					"      <i>" + gdTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"green\">&nbsp;</em>" +
					"      <b>待接收</b>" +
					"      <i>" + djsTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>处理</b>" +
					"      <i>" + clTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>完成</b>" +
					"      <i>" + wcTime + "</i>" +
					"    </p>";
				}
				break;
			case 3:
				{
					html =
					"  <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>告警</b>" +
					"      <i>" + gjTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>工单</b>" +
					"      <i>" + gdTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>待接收</b>" +
					"      <i>" + djsTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"green\">&nbsp;</em>" +
					"      <b>处理</b>" +
					"      <i>" + clTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"white\">&nbsp;</em>" +
					"      <b>完成</b>" +
					"      <i>" + wcTime + "</i>" +
					"    </p>";
				}
				break;
			case 4:
				case 5:
				{
					html =
					"  <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>告警</b>" +
					"      <i>" + gjTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>工单</b>" +
					"      <i>" + gdTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>待接收</b>" +
					"      <i>" + djsTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em>&nbsp;</em>" +
					"      <b>处理</b>" +
					"      <i>" + clTime + "</i>" +
					"    </p>" +
					"    <p>" +
					"      <em class=\"green\">&nbsp;</em>" +
					"      <b>完成</b>" +
					"      <i>" + wcTime + "</i>" +
					"    </p>";
				}
				break;

			default:
		}

		console.log("返回的html-------"+html);
		$(".record_step").html(html);
	}

	Date.prototype.format = function(format) //author: meizz
	{
		var o = {
			"M+": this.getMonth() + 1, //month
			"d+": this.getDate(), //day
			"h+": this.getHours(), //hour
			"m+": this.getMinutes(), //minute
			"s+": this.getSeconds(), //second
			"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
			"S": this.getMilliseconds() //millisecond
		}
		if(/(y+)/.test(format)) format = format.replace(RegExp.$1,
			(this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("(" + k + ")").test(format))
				format = format.replace(RegExp.$1,
					RegExp.$1.length == 1 ? o[k] :
					("00" + o[k]).substr(("" + o[k]).length));
		return format;
	}

	function formatTime(val) {
		if(val == null || val == "" || typeof(val) == "undefined") {
			return "";
		}

		var ready = val.toString();
		ready = ready.replace(/\-/g, "/");
		var d = new Date(ready);
		var tmp = d.format("yyyy-MM-dd hh:mm:ss");
		return tmp;
	}

	var noEmoji = function(dom) {
		var html = "",
			oldHtml = "";
		if('INPUT' == dom.tagName) {
			html = $(dom).val();
		}
		oldHtml = html;
		var reg = /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
		if(html.match(reg)) {
			html = html.replace(reg, '');
		}

		if(html != oldHtml) {
			if('INPUT' == dom.tagName) {
				$(dom).val(html);
			}
		}
		/**
		 * 光标移到最后
		 */
		function endFocus(dom) {
			var sel = window.getSelection();
			var range = document.createRange();
			range.selectNodeContents(dom);
			range.collapse(false);
			sel.removeAllRanges();
			sel.addRange(range);
		}
	};

	//$(".noEmojiText").on("keyup",funtion(){
	//		noEmoji($(this));
	//
	//});

	$('.noEmojiText').keyup(function() {
		noEmoji($(this));
	})


	//上传图片相关方法

			function settingImgs(imgList) {

					var newUrl = imgList[0];
					if(sp.imgs != null || sp.imgs.length > 0) {
						if(sp.imgs.length < 3) {
							sp.imgs.push(newUrl);

						} else {
							sp.imgs.splice(0, 1, newUrl);

						}
					} else {
						sp.imgs.push(newUrl);
						console.log(newUrl);
					}

					//							alert(sp.imgs.splice(","));
					sp.params.url = sp.imgs.join(",");

					console.log("sp.params.url----" + sp.params.url);
					console.log("sp.imgs--" + JSON.stringify(sp.imgs));

				}

				document.getElementById('selectImgBtn').addEventListener('tap', function() {
					if(mui.os.plus) {
						var a = [{
							title: "拍照"
						}, {
							title: "从手机相册选择"
						}];
						plus.nativeUI.actionSheet({
							title: "选择照片",
							cancel: "取消",
							buttons: a
						}, function(b) { /*actionSheet 按钮点击事件*/
							switch(b.index) {
								case 0:
									break;
								case 1:
									getImage(); /*拍照*/
									break;
								case 2:
									galleryImg(); /*打开相册*/
									break;
								default:
									break;
							}
						})
					}
				}, false);

				//拍照上传
				//拍照 
				function getImage() {
					var c = plus.camera.getCamera();
					c.captureImage(function(e) {
						plus.io.resolveLocalFileSystemURL(e, function(entry) {
							var s = entry.toLocalURL() + "?version=" + new Date().getTime();
							uploadHead(s); /*上传图片*/
						}, function(e) {
							console.log("读取拍照文件错误：" + e.message);
						});
					}, function(s) {
						console.log("error" + s);
					}, {
						filename: "_doc/head.png"
					})
				}

				//从相册选图上传
				//本地相册选择 
				function galleryImg() {
					// 从相册中选择图片
					plus.gallery.pick(function(e) {
						for(var i in e.files) {
							var fileSrc = e.files[i]
							//	    	setHtml(fileSrc);
							console.log(fileSrc);
							uploadHead(fileSrc);
						}
					}, function(e) {
						console.log("取消选择图片");
					}, {
						filter: "image",
						multiple: true,
						maximum: 3,
						system: false,
						onmaxed: function() {
							plus.nativeUI.alert('最多只能选择3张图片');
						}
					});

				}

				//图片上传和压缩
				//上传头像图片 
				function uploadHead(imgPath) {
					console.log("imgPath = " + imgPath);
					//          mainImage.src = imgPath; 
					//          mainImage.style.width = "60px"; 
					//          mainImage.style.height = "60px"; 

					var image = new Image();
					image.src = imgPath;
					image.onload = function() {
						var imgData = getBase64Image(image);
						/*在这里调用上传接口*/

						hui.loading("图片上传中...");

						var username = localStorage.getItem("username");
						var sec = localStorage.getItem("sec_pwd");
						var time = apiManage.getNow();
						var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
						var paramKey = hex_md5(key);
						var jsonParam = JSON.stringify({
							loginName: username,
							time: time,
							key: paramKey
						});

						var path = urlManager.uploadFile();
						console.log("path-------" + path);

						var form = new FormData();
						//console.log("base64----"+base64String);
						form.append("imgCode", imgData);
						$.ajax({
							type: "POST",
							url: path,
							data: form,
							contentType: false, // 注意这里应设为false
							processData: false, //false
							beforeSend: function(request) {
								request.setRequestHeader("loginName", username);
								request.setRequestHeader("time", time);
								request.setRequestHeader("sign", paramKey);
							},
							success: function(data) {
								console.log("return data-------------" + JSON.stringify(data));
								var imgList = data.pathlist;
								hui.closeLoading();
								settingImgs(imgList);
							}
						});

					}
				}
				//将图片压缩转成base64 
				function getBase64Image(img) {
					var canvas = document.createElement("canvas");
					var width = img.width;
					var height = img.height;

					var settingWH = 500; //限制宽高 
					// calculate the width and height, constraining the proportions 
					if(width > height) {
						if(width > settingWH) {
							height = Math.round(height *= settingWH / width);
							width = settingWH;
						}
					} else {
						if(height > settingWH) {
							width = Math.round(width *= settingWH / height);
							height = settingWH;
						}
					}
					canvas.width = width; /*设置新的图片的宽度*/
					canvas.height = height; /*设置新的图片的长度*/
					var ctx = canvas.getContext("2d");
					ctx.drawImage(img, 0, 0, width, height); /*绘图*/
					var dataURL = canvas.toDataURL("image/png", 0.8);
					return dataURL.replace("data:image/png;base64,", "");
				}



});